package com.chcit.mobile.mvp.ui.adapter;

import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseViewHolder;
import com.chcit.mobile.R;
import com.chcit.mobile.helper.recycler.BaseSelectQuickAdapter;
import com.chcit.mobile.mvp.model.entity.ReceiveBean;


import java.util.List;

public class ReceiveAdapter extends BaseSelectQuickAdapter<ReceiveBean,BaseViewHolder> {

    private View.OnClickListener mOnClickListener;
    public ReceiveAdapter(@Nullable List<ReceiveBean> data) {
        super(R.layout.item_receive_data,data);


    }

    public void setOnClickListener(View.OnClickListener onClickListener){
        mOnClickListener = onClickListener;
    }
    @Override
    protected void convert(final BaseViewHolder helper, final ReceiveBean item) {

        CheckBox checkBox = helper.getView(R.id.box_puchase_select);
        int position= helper.getAdapterPosition();
        checkBox.setChecked(mSelectedPositions.get(position));
        checkBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int i= helper.getAdapterPosition();
                if (isItemChecked(i)) {
                    setItemChecked(i, false);
                } else {
                    setItemChecked(i, true);
                }

                if (mTitleBarView != null) {
                    String msg = "已选择" + getSelectedItem().size() + "/" + getItemCount();
                    mTitleBarView.setText(msg);
                }
                notifyItemChanged(i);
            }
        });
        LinearLayout l1 = helper.getView(R.id.ll_first);
        l1.setOnClickListener(v->{
            checkBox.performClick();
        });
        final TextView textView = helper.getView(R.id.tv_puchase_deal);
        textView.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                if(mOnClickListener != null){
                    v.setTag(item);
                    mOnClickListener.onClick(v);
                }
            }
        });
        helper.setText(R.id.tv_puchase_GuaranteeDate,item.getGuaranteeDate());
        helper.setText(R.id.tv_puchase_Lot,item.getLot());
        helper.setText(R.id.tv_puchase_Manufacturer,item.getManufacturer());
        helper.setText(R.id.tv_puchase_pname,item.getProductName());
        helper.setText(R.id.tv_puchase_StorageStatusName,item.getLPackageQty().intValue()+"");
        helper.setText(R.id.tv_puchase_productCode,item.getDeliveryNo());
        helper.setText(R.id.tv_puchase_VendorName,item.getBpartnerName());
        helper.setText(R.id.tv_puchase_QtyOnHand,item.getQtyArrived().intValue()+"");
        helper.setText(R.id.tv_puchase_productSpec,item.getProductSpec());
       // helper.setText(R.id.tv_puchase_odd,item.getOddPackageCount()+"包/"+(item.getOddQty()==null?"0":item.getOddQty())+item.getUomName());
       // helper.setText(R.id.tv_puchase_unit,item.getUnitPackageCount()+"包/"+item.getUnitQty()+item.getUomName());

    }



}
